//
//  MainView.swift
//  TestActorLibraryProject
//
//  Created by rolodestar on 2025/5/20.
//

import SwiftUI
import TestActorLibrary

struct MainView: View {
    @StateObject var actor: MyMainStatus = MyMainStatus.shared
    @StateObject var viewModel: ViewModel = ViewModel()
    @StateObject var viewModel2: ViewModel = ViewModel()
    @State var threadInfo: String = ""
    var body: some View {
        VStack{
            Text("\(threadInfo)")
            Text("actor status:\(actor.playStatus)!")
            Button {
                getThreadInfo()
                
                Task{
                    await viewModel.play()
                    getThreadInfo()
                }
            } label: {
                Text("play")
            }
            Button {
                Task{@MainActor in
                    await viewModel.pause()
                }
            } label: {
                Text("pause")
            }
            Button {
                Task{@MainActor in
                    await viewModel.stop()
                }
            } label: {
                Text("stop")
            }
            Button {
                getThreadInfo()
                
                Task{
                    await viewModel2.play()
                    getThreadInfo()
                }
            } label: {
                Text("play2")
            }
            Button {
                getThreadInfo()
                Task.detached{
                    await getThreadInfo()
                    await viewModel2.pause()
                }
            } label: {
                Text("pause2")
            }
            Button {
                Task{@MainActor in
                    await viewModel2.stop()
                }
            } label: {
                Text("stop2")
            }
            Spacer()

        }
    }
    func getThreadInfo() {
        let current = Thread.current
        self.threadInfo += "\(current)\n"
    }
}

#Preview {
    MainView()
}
